﻿Imports MeoTom.Core.BLL
Imports MeoTom.Core

Partial Public Class LinkCreate
    Inherits System.Web.UI.Page

    Private ReadOnly _lnk As New BLL.Link()
    Private ReadOnly _cat As New LinkCat()
    Private ReadOnly _util As New Utilities.Common()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim previousPage As String = ""
        If Request.QueryString.ToString = vbNullString Then
            previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
        Else
            previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
        End If
        _util.ValidateLogin(previousPage)

        catdetail.InnerHtml = _cat.WriteLinkCat(0)
    End Sub

    Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCreate.Click
        _lnk.IsPrivate = chkIsPrivate.Checked
        _lnk.LinkAddress = _util.NoHTML(txtLink.Text)
        _lnk.LinkDesc = _util.NoHTML(txtDesc.Text)
        _lnk.LinkName = _util.NoHTML(txtName.Text)
        _lnk.TargetType = Integer.Parse(Request.Form("cboTarget"))

        _lnk.Create()

        If Request.Form.Get("cboCategory") = vbNullString Then
            _lnk.LinkCat = 1
            _lnk.LinkID = 0
            _lnk.SetTempLinkCat(0)
        Else
            For Each strCatID As String In Regex.Split(Request.Form("cboCategory").ToString(), ",")
                _lnk.LinkCat = Integer.Parse(strCatID)
                _lnk.LinkID = 0
                _lnk.SetTempLinkCat(0)
            Next
        End If
        _cat.WriteLinkCat(5)
        Response.Redirect("/mt-inside/LinkManager.aspx")
    End Sub
End Class